package com.wangzh.concurrent.lock.lock8;

import java.util.concurrent.TimeUnit;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        Phone phone = new Phone();
        Phone phone1 = new Phone();

        Thread a = new Thread(phone::sendSms, "A");
        Thread b = new Thread(phone::call, "B");

        TimeUnit.MILLISECONDS.sleep(1000);
        a.start();

        b.start();

    }
}
class Phone{
//    synchronized 锁的对象是方法的调用者对象也就是new的对象,静态方法锁的是Class对象
    public synchronized void sendSms(){
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("发短信");
    }
    public synchronized void call(){
        System.out.println("打电话");
    }

}
